/**
 * @Title: drugStoreIntgrityList_ctrl.js
 * @Description: TODO
 * Copyright: Copyright (c) 2015
 * Company:中国平安
 *
 * @Project HIMS-FWA
 * @author EX-CHENLIN002
 * @date 2015年2月12日 上午11:29:35
 * @version V1.0
 */
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('DrugStoreIntgrityCtrl',['$scope', 'BaseURL','Modal','DrugStoreService','CommunityService','$state',
	                             function($scope, baseUrl, Modal, DrugStoreService,CommunityService,$state) {
//		$scope.drugStoreService = DrugStoreService;
//		DrugStoreService.initMedicalOrgInfoList();
		$scope.communityService = CommunityService;
		CommunityService.initPharmacyDatas();
		//查询条件 对象
		$scope.form = {};
		
		//分页配置
		$scope.current = {
							currentPage: 0,  
							limit: 20
						 };
		//表头
		$scope.columns = [];
		
		$scope.evaluationScroes = [
		                           {"name":"≥95分","code":"95"},
		                           {"name":"≥76分","code":"76"}
		                          ];
		var maps = ['one','two','three','four'];
		//获取表头考评得分
		function getTheadScore() {
			var params = getParams();
			DrugStoreService.getEvaluationName(params).success(function (res) {
				var width = 80;
				if (res.list && res.list.length > 0) {
					width = 80/res.list.length;
				}
				var columns = [{label:"合计",map:"total",width:"20%"}];
				angular.forEach(res.list,function(data,i) {
					var column = {};
					column.label = data;
					column.map = maps[i];
					column.width = width;
					columns.push(column);
				});
				$scope.columns = columns;
			});
		}
		
		
		$scope.form = {};
		$scope.loading = false;
		
		
		//获取参数
		function getParams() {
			var params = {
					currentPage: $scope.current.currentPage,
					limit: $scope.current.limit,
					orgName: $scope.form.orgName,
					evaluationYear: $scope.form.evaluationYear,
					bedName: $scope.form.bedName,
					evaluationScroe: $scope.form.evaluationScroe
				};
			return params;
		}
		
		
		/**
		 * 考评操作
		 */
		$scope.operation=function (data){
			var status=data.status;
			if (status=='6') { //已经完成了
				$state.go('drugStoreIntgrityManager.finishDrugStore',{evaluationCode:data.evaluationCode});
			}
			else if (status == '1' || status == '2') {//待考评的
				$state.go('drugStoreIntgrityManager.updateDrugStore',{evaluationCode:data.evaluationCode});
			}
			else if (status == '3') {//撤销操作
				$state.go('drugStoreIntgrityManager.cancelIntgrity',{evaluationCode:data.evaluationCode});
			}
		}
		
		$scope.loading = false;
		//查询
		function query() {
			var params = getParams();
			if(!$scope.form.evaluationYear){
				Modal.alert("考评年度必录！");
				return ;
			}
			params.processStatus=[1,2,6]; //带考评,审核退回,已经完成
			params.evalautionType = '0';	//考评类别：0：机构，1,药店
			$scope.loading = true;
			DrugStoreService.getEvaluationOrgList(params).success(function(res){
				$scope.tableData = res.orgList;
				$scope.totalCount = res.orgCount;
				$scope.loading = false;
			}).error(function(e){
				$scope.loading = false;
				Modal.alert("error");
			});
			
			getTheadScore();
		}
		
		//查询
		$scope.onSubmit = function() {
			$scope.current.currentPage = 1;
			query();
		}
		
		//重置
		$scope.onReset = function() {
			$scope.form = {};
		}
		
		//分页监听
		$scope.$on('pageTool.skipPage',function(e,v){
			$scope.current.currentPage = v;
			query();
		});
		
		//初始化年份
		CommunityService.initDate("yyyy").success(function(res){
			$scope.form.evaluationYear = res.formatDate;
			//页面加载时调用
			$scope.onSubmit();
		});
		
	}]);
})();